<template>
    <div class="icon-div">
      <swiper :options="swiperOption">
        <swiper-slide v-for="(page, index) of pages" :key="index">
          <div class="icon-item"
               v-for="obj of page"
               :key="obj.id"
          >
            <div class="item-img">
              <img class="item-img-content" :src="obj.imgUrl"/>
            </div>
            <p class="item-text">{{obj.desc}}</p>
          </div>
        </swiper-slide>
      </swiper>
    </div>
</template>

<script>
export default {
  name: 'Icons',
  props: {
    iconlist: Array
  },
  computed: {
    pages: function () {
      const pages = []
      this.iconlist.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl';
  .icon-div >>> .swiper-container {
    height: 0;
    padding-bottom: 50%;
  }
  .icon-div {
    overflow: hidden;
    height: 0;
    padding-bottom: 50%;
  }
  .icon-item {
    overflow: hidden;
    height: 0;
    width: 25%;
    padding-bottom: 25%;
    float: left;
    position: relative;
  }
  .item-img {
    position: absolute;
    top:0;
    left: 0;
    right: 0;
    bottom: .44rem;
    box-sizing: border-box;
    padding: .1rem;
  }

  .item-img-content {
    height: 100%;
    display: block;
    margin: 0 auto;
  }
  .item-text {
    text-align: center;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    line-height: .44rem;
    color: $darkTextColor;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
</style>
